package com.acme.bankapp.domain.bank;

import com.acme.bankapp.domain.Exceptions.OverDraftLimitExceededException;

public class CheckingAccount extends AbstractAccount {

	private double overdraft;
	
	// TODO: define constructor 
	public CheckingAccount(final double amount, final double overdraft) {
		super(amount);
		this.overdraft = overdraft;
	}
	
	public CheckingAccount() { 
		this(0, 1000);
	}
	
	public double maximumAmountToWithdraw() {
		return this.balance + overdraft;
	}
	
	public void deposit(final double amount) throws IllegalArgumentException {
		if(amount <= 0) {
			throw new IllegalArgumentException("the wrong amount");
		} 
		this.balance += amount;	
	}
		
	public void withdraw(final double amount) throws IllegalArgumentException, OverDraftLimitExceededException {		
		
		if(amount < 0)
		{
			throw new IllegalArgumentException("the wrong amount");
		}
		
		//assert ((this.balance + overdraft) >= amount): "there is not enough money";
	   if ((this.balance + overdraft) < amount) {
			throw new OverDraftLimitExceededException("the wrong amount", -(this.balance + overdraft - amount));
		}
		this.balance -= amount;	
				
	}

}
